package com.hdu.clj.dncard.databaseUtil

import android.content.ContentValues
import android.content.Context
import android.util.Log
import com.hdu.clj.dncard.database.AllEquipDatabase
import com.hdu.clj.dncard.database.EquipmentDatabase
import com.hdu.clj.dncard.util.EquipAttr
import com.hdu.clj.dncard.util.Equipment

/**
 * 装备类
 * armor 铠甲
 * helmet 头盔
 * boots 战靴
 * glove 手套
 * weapon 武器
 */
class AllEquipDatabaseUtil {
    fun insert(context: Context, ver:Int, equip:Equipment,acc:String){
        val dbAll = AllEquipDatabase(context,"AllEquip",ver)
        val dba = dbAll.writableDatabase
        val values = ContentValues().apply {
            put("acc",acc)
            put("armor",equip.armor)
            put("helmet",equip.helmet)
            put("boots",equip.boots)
            put("glove",equip.glove)
            put("weapon",equip.weapon)
        }
        dba.insert("AllEquip", null, values)
    }

    fun update(context: Context,eid:String,acc:String){
        val dbAll = AllEquipDatabase(context,"AllEquip",1)
        val dba = dbAll.writableDatabase
        val new_id = eid.toInt()
        if (new_id<20000){
            dba.execSQL("update AllEquip set armor = ? where acc = ?", arrayOf(eid,acc))

        }
        else if (new_id<30000){
            dba.execSQL("update AllEquip set helmet = ? where acc = ?", arrayOf(eid,acc))

        }
        else if (new_id<40000){
            dba.execSQL("update AllEquip set boots = ? where acc = ?", arrayOf(eid,acc))

        }
        else if (new_id<50000){
            dba.execSQL("update AllEquip set glove = ? where acc = ?", arrayOf(eid,acc))

        }
        else{
            dba.execSQL("update AllEquip set weapon = ? where acc = ?", arrayOf(eid,acc))

        }
    }
}